package com.hzy.config;

import cn.itcast.pojo.Country;
import cn.itcast.pojo.Province;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class CommonConfig {
    //注入country对象
    //如果配置文件中配置了指定的信息，就注入。否则不注入
    @ConditionalOnProperty(prefix = "country",name = {"name","system"})
    @Bean
    public Country country(@Value("${country.name}") String name,@Value("${country.system}") String system){
        Country country = new Country();
        country.setName(name);
        country.setSystem(system);
        return country;
    }

    //对象默认的名字是：方法名
    //@Bean("aa")
    //如果方法的内部需要使用ioc容器中已经存在的bean对象，那么只需要在方法上声明即可，spring会自动的注入
    @Bean
    public Province province(){
        return new Province();
    }
}
